package com.snoob.springCloudGateway.filter.gatewayFiler.ip;

import com.snoob.springCloudGateway.configurer.properties.CustomProperties;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @描述: TODO IP网关过滤器工厂，需要为相关路由配置上才可生效
 * @作者: lixing
 * @日期 2021/6/24 10:25
 */
@Component
public class MyIpGatewayFilterFactory extends AbstractGatewayFilterFactory<MyIpGatewayFilterFactoryConfig> {
    @Resource
    private CustomProperties customProperties;

    public MyIpGatewayFilterFactory() {
        super(MyIpGatewayFilterFactoryConfig.class);
    }

    /** 自定义配置类-内部类，用于传入配置参数 */
    @Override
    public List<String> shortcutFieldOrder() {
        return Collections.singletonList("whiteIp");
    }

    /**
     * 过滤器逻辑
     */
    @Override
    public GatewayFilter apply(MyIpGatewayFilterFactoryConfig config) {
        return new MyIpGatewayFilter(customProperties, config);
    }

}
